<?php
class Login_Model_Login {
	
	/**
	 * session handler
	 * @var sessionStart
	 */
	public $sessionStart;
	
	/**
	 * form data initialization
	 * 
	 * @var $formData
	 */
	public $formData;
	
	public function __construct(){
		
		$this->sessionStart = new Core_Model_Session();
		$this->formData = new Login_Data_Loginform();
		
	}
	
	public function getLoginData($postVars){
		
		if(isset($postVars['login']) && isset($postVars['password'])){
			
			$login = $postVars['login'];
			$password = $postVars['password'];
			
			$this->sessionInit($login , $password);
			
		}
		else {
			
			$article = $this->formData->getLoginForm();
			
			return $article;
			
		}
		
	}
	
	public function sessionInit($login, $password){
		if(($this->loginValidation($login) === TRUE) && ($this->passwordValidation($password) === TRUE)){
			
			$this->sessionStart->sessionInitialization($login, $password);
			
		}
		else {
			
			echo '<meta http-equiv="Refresh" content="0;url='.SITE_ROOT.'login.html">';
		
		}
	}
	
	/**
	 * password validation
	 * 
	 * @param string $password
	 * @return boolean
	 */
	public function passwordValidation($password){
		
		if(trim($password) != ""){
			
			return TRUE;
			
		}
		else {
			
			return FALSE;
			
		}
	}
	
	/**
	 * check login
	 * 
	 * @param string $login
	 * @return boolean
	 */
	public function loginValidation($login){
		
		if(trim($login) != ""){

			return TRUE;
		
		}
		else {

			return FALSE;
		
		}
	}
	
}